Skip to content

fix(AlertGroup): update AlertGroupInline to not use child index as a key#7878

Merged
tlabaj merged 4 commits into
patternfly:mainfrom
wise-king-sullyman:alert-group-inline-index-key
Sep 1, 2022
Merged

fix(AlertGroup): update AlertGroupInline to not use child index as a key#7878
tlabaj merged 4 commits into
patternfly:mainfrom
wise-king-sullyman:alert-group-inline-index-key

Conversation

@wise-king-sullyman
Copy link
Copy Markdown
Collaborator

@wise-king-sullyman wise-king-sullyman commented Aug 22, 2022

What: Closes #7877

Additional issues:

Needed for #7843

Note: I added an integration test rather than unit tests as I couldn't identify a good way to unit test either side of the Alert/AlertGroup/AlertGroupInline interaction. This is because Alert doesn't do anything with uniqueId and AlertGroupInline just applies it as a key.

@patternfly-build
Copy link
Copy Markdown
Collaborator

patternfly-build commented Aug 22, 2022

@wise-king-sullyman wise-king-sullyman marked this pull request as ready for review August 23, 2022 20:15
Comment on lines +22 to +23
{React.Children.toArray(children).map((alert, index) => (
<li key={(alert as React.ReactElement<AlertProps>).props?.uniqueId || index}>{alert}</li>
Copy link
Copy Markdown
Contributor

@tompsota tompsota Aug 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been thinking if it is the best solution to add the uniqueId prop as it is intended only for 'internal' use. Also, it may be a bit confusing for the user when the expected behavior of the alert depends on prop that is optional.

What if we generated e.g. uuid and used it as key instead? This would however require either to use a 3rd party package or write a generator, I've seen a couple of good implementations for example here.

I'm aware that there are some drawbacks when using uuids. Therefore I'll be fine also with uniqueId prop, but wanted to bring up the other option too :)

UPDATE:
We discussed this suggestion off GitHub and it looks like uuid doesn't solve the problem.
I agree with adding the uniqueId prop.

/** Adds accessible text to the alert Toggle */
toggleAriaLabel?: string;
/** Uniquely identifies the alert */
uniqueId?: string;
Copy link
Copy Markdown
Contributor

@tlabaj tlabaj Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use id?

Copy link
Copy Markdown
Contributor

@tlabaj tlabaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tlabaj tlabaj merged commit 1637b27 into patternfly:main Sep 1, 2022
@wise-king-sullyman wise-king-sullyman deleted the alert-group-inline-index-key branch September 2, 2022 13:02
andyyvo pushed a commit to andyyvo/patternfly-react that referenced this pull request Sep 9, 2022
…key (patternfly#7878)

* fix(AlertGroup): update AlertGroupInline to not use child index as a key

* add index as backup key in case an alert is missing a uniqueId

* add tests

* change prop name uniqueId -> id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug - AlertGroup - AlertGroupInline usage of index as key causes issues when alert order is reversed

4 participants